import java.util.concurrent.Callable;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zxs
 * @create 2021-03-30 19:21
 */
public class MyThread extends Thread {
    private Integer integer = 1;
    private String str1 = "1";
    private String str2 = new String("zxs");
    private Boolean bool = Boolean.FALSE;


    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + " run " + i + "times");
        }
        synchronized (str2) {
            System.out.println("zxs");
        }
    }
}

class MyRunnable implements Runnable {
    private static int count = 15;

    @Override
    public void run() {
        synchronized (MyRunnable.class) {
            for (int i = 0; i < 10; i++) {
                if (count > 0) {
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count -= 1;
                    System.out.println(" 剩余数量 " + count + " 个 ");
                }
            }
        }
    }
}

class MyRunnable1 implements Runnable {
    private static int count = 15;

    @Override
    public void run() {
        Lock lock = new ReentrantLock();
        lock.lock();
        try {
            for (int i = 0; i < 10; i++) {
                if (count > 0) {
                    count -= 1;
                    System.out.println(" 剩余数量 " + count + " 个 ");
                }
            }
        } finally {
            lock.unlock();
        }
    }
}

class MyCallable implements Callable<String>{
    @Override
    public String call() throws Exception {
        Thread.sleep(5000);
        return "长坂英雄尚在";
    }
}